package com.wlyuan.index.domain.index.event;

import com.wlyuan.core.domain.event.DomainEvent;
import com.wlyuan.core.domain.valueobj.CombineId;
import com.wlyuan.core.domain.valueobj.QuotationId;
import com.wlyuan.core.domain.valueobj.WaybillId;
import com.wlyuan.index.api.dto.QuotationIndexDTO;
import com.wlyuan.index.domain.source.utils.SourceUtils;
import lombok.AllArgsConstructor;
import lombok.Getter;

/**
 * @author yuanjie
 */
@AllArgsConstructor
@Getter
public class CombineQuoteUpdated implements DomainEvent {
    private final QuotationIndexDTO quotation;

    public QuotationId getQuotationId() {
        return new QuotationId(quotation.getQuotationId());
    }

    public <T> T getBusinessId() {
        if (SourceUtils.isCombineQuote(quotation)) {
            return (T) new CombineId(quotation.getSourceId());
        } else if (SourceUtils.isWaybillQuote(quotation)) {
            return (T) new WaybillId(quotation.getSourceId());
        }
        return null;
    }
}
